package com.hbt.feature_provider.controller;

import com.hbt.api.entity.CommonResult;
import com.hbt.feature_provider.service.FeatureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("feature_provider")
public class FeatureProviderController {

    @Autowired
    FeatureService featureService;

    @PostMapping("del_feature")
    public CommonResult<String> delFeature(String descript, int wordid){
        int count = 0;
        count = featureService.delFeature(descript, wordid);
        CommonResult<String> result = new CommonResult<String>();
        result.setMsg(count>0?"删除特征成功":"删除特征失败");
        result.setT(count>0?"删除特征成功":"删除特征失败");
        return result;
    }

    @PostMapping("add_feature")
    public CommonResult<String> addFeature(String descript, int wordid){
        int count = 0;
        count = featureService.addFeature(descript, wordid);
        CommonResult<String> result = new CommonResult<String>();
        result.setMsg(count>0?"添加特征成功":"添加特征失败");
        result.setT(count>0?"添加特征成功":"添加特征失败");
        return result;
    }


    @RequestMapping("changeSysFeatures")
    public int changeSysFeatures(@RequestParam("features") List<String> features, int userid){
        System.out.println("enter feature provider conttoller changeSysFeatures");
        System.out.println("enter feature provider conttoller changeSysFeatures feature length:"+features.size());
        System.out.println("enter feature provider conttoller changeSysFeatures userid:"+userid);
        return featureService.changeSysFeatures(features,userid);
    }

    @RequestMapping("getSysFeatures")
    public List<String> getSysFeatures(int userid){
        System.out.println("enter controller getSysFeatures");
        return featureService.getSysFeatures(userid);
    }


}
